"""
image_processing2.py将灰度图大小压缩至28x28，并将数据转成csv文件
"""
import numpy as np
from PIL import Image
import cv2
import os

IMG_DIR = 'C:\\Users\\86187\\Desktop\\2021 machine learning\\homework\\machinelearning_homework-master\\report_03_Fashion\\taobao\\shoes'

for img in os.listdir(IMG_DIR):
    img_array = cv2.imread(os.path.join(IMG_DIR,img), cv2.IMREAD_GRAYSCALE)

    img_pil = Image.fromarray(img_array)
    img_28x28 = np.array(img_pil.resize((28, 28), Image.ANTIALIAS))

    img_array = (img_28x28.flatten())

    img_array  = img_array.reshape(-1,1).T

    print(img_array)

    with open('shoes.csv', 'ab') as f:

        np.savetxt(f, img_array, delimiter=",")